﻿using Abp.AspNetCore.Mvc.Controllers;
using Magicodes.WeChat.Application.QRCode;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Magicodes.WeChat.Web.Core
{
    [AllowAnonymous]
    [Route("WeChatQRCode")]
    public class WeChatQRCodeController : AbpController
    {
        public IWeChatQRCodeAppService WeChatQRCodeAppService { get; set; }

        /// <summary>
        /// 返回生成的二维码
        /// </summary>
        /// <param name="key">业务key，比如微信绑定、推荐</param>
        /// <param name="value">业务值</param>
        /// <returns></returns>
        [HttpGet("")]
        public async Task<ActionResult> QRCode(string key, string value)
        {
            var result = await WeChatQRCodeAppService.CreateQrCode(new Application.QRCode.Dto.CreateQRCodeInput()
            {
                Key = key,
                Value = value
            });

            var url = await WeChatQRCodeAppService.GetQrCodeUrl(result.Ticket);
            return Redirect(url: url);
        }
    }
}
